﻿/*
{
"状态":1,
"名称":"新增-角色用户资料",
"作者":"陈泽椿",
"创建时间":"2018-06-30",
"功能":"新增-角色用户资料",
"log": [
	{"date":"06-01" , "dev" :"hzhh" , "content" : ""}
]
}
*/


DECLARE @user_keys VARCHAR(8000)
DECLARE @role_keys VARCHAR(8000)

SET @user_keys='{user_keys}'
SET @role_keys='{role_keys}'

if isnull(@user_keys,'')=''
begin 
	RAISERROR ('SQL:用户不允许为空', 16 ,1 ) ; 
	return
end 

if isnull(@role_keys,'')=''
begin 
	RAISERROR ('SQL:角色不允许为空', 16 ,1 ) ; 
	return
end 


INSERT INTO y_role_user(user_key,role_key,create_time,update_time)
SELECT A.user_key,A.role_key,GETDATE(),GETDATE() FROM 
(
SELECT CONVERT(INT,A.value) AS user_key,CONVERT(INT,B.value) AS role_key
FROM dbo.Ft_Split(@user_keys,',') A CROSS JOIN dbo.Ft_Split(@role_keys,',') B
) A LEFT JOIN dbo.y_role_user B ON B.role_key = A.role_key AND B.user_key = A.user_key
WHERE B.user_key IS NULL 
